<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>首页</title>
    <!-- zui css -->
    <link rel="stylesheet" th:href="@{/zui/css/zui.min.css}">

    <!-- jquery js -->
    <script th:src="@{/zui/lib/jquery/jquery.js}"></script>

    <!-- zui js -->
    <script th:src="@{/zui/js/zui.min.js}"></script>
    <style>
        body {
            padding: 0;
            margin: 0;
        }
    </style>
</head>
<body>
<nav class="navbar navbar-default" role="navigation">
    <div class="container-fluid">
        <!-- 导航头部 -->
        <div class="navbar-header">
            <a class="navbar-brand" href="javascript:history.go(-1)"><i class="icon-chevron-left"></i></a>
            <span class="navbar-brand">未知文档 </span>
        </div>
        <!-- 导航项目 -->
        <div class="collapse navbar-collapse navbar-collapse-example">
            <!-- 右侧的导航项目 -->
            <ul class="nav navbar-nav navbar-right">
                <li><a th:href="@{/app/my/info}" title="收藏"><i class="icon-heart-empty"></i></a></li>
                <li><a th:href="@{/app/my/info}">吴宗波</a></li>
            </ul>
        </div><!-- END .navbar-collapse -->
    </div>
</nav>
<div class="container wraper-bg">
    <input type="text" class="form-control"  placeholder="请输入标题" id="title">
    <textarea class="form-control" id="content" placeholder="请输入内容" id="content" required="required"></textarea>
    <button class="btn btn-block " type="button" onclick="saveArticle()" style="margin-top:40px ">保存</button>
</div>
<script type="text/javascript" th:src="@{/zui/lib/tinymce/js/tinymce/tinymce.min.js}"></script>
<script type="text/javascript">
    tinymce.init({
        selector : '#content',
        height : 400,
        language : 'zh_CN',
        plugins : ['autolink','link','image'], //数组方式
        toolbar: false,
        images_upload_handler: function (blobInfo, succFun, failFun) {
            var xhr, formData;
            var file = blobInfo.blob();//转化为易于理解的file对象
            xhr = new XMLHttpRequest();
            xhr.withCredentials = false;
            xhr.open('POST', '/admin/upload/cosupload');
            xhr.onload = function() {
                var json;
                if (xhr.status != 200) {
                    failFun('HTTP Error: ' + xhr.status);
                    return;
                }
                json =JSON.parse(xhr.responseText);
                /*  if (!json || typeof json.location != 'string') {
                     failFun('Invalid JSON: ' + xhr.responseText);
                     return;
                 } */


                if(json.status==1){

                    //console.log(json.path)
                    succFun(json.path);
                }
                else{
                    failFun('Invalid JSON: ' + xhr.responseText);
                    return;

                }

            };
            formData = new FormData();
            formData.append('file', file, file.name );//此处与源文档不一样
            xhr.send(formData);
        }

    })

    function saveArticle(){

        let title=$("title").val();
        let content=$("content").val();
        let params={
            title:title,
            content:content
        };
        $.post("",params,function (){


        })

    }
</script>
</body>
</html>